package com.virtium.vpc.action.controller;

import java.util.ArrayList;
import java.util.Iterator;
import com.virtium.vpc.dao.DAOFactory;
import com.virtium.vpc.dao.VpcCongigurationDAO;
import com.virtium.vpc.hibernate.model.VpcCongiguration;


public class VpcConfigurationManager {
	private static ArrayList<VpcCongiguration> arrVpcCongiguration = null;

	public static ArrayList<VpcCongiguration> getAll() {
		try {
			if (arrVpcCongiguration != null && arrVpcCongiguration.size() > 0)
				return arrVpcCongiguration;
			VpcCongigurationDAO vpcCongigurationDAO = DAOFactory.getInstance()
					.getVpcCongigurationDAO();
			arrVpcCongiguration = new ArrayList<VpcCongiguration>();
			arrVpcCongiguration.addAll(vpcCongigurationDAO.findAll());
		} catch (Exception ex) {
		}
		return arrVpcCongiguration;
	}
	
	public static String getTextByID(int id){
		getAll();
		Iterator<VpcCongiguration> iterObject = arrVpcCongiguration.listIterator();
		while(iterObject.hasNext()){
			VpcCongiguration object = iterObject.next();
			if(object.getId().equals(id))return object.getText();
			
		}
		return "";
	}
	
	public static void AddNew(String text){
		try{
			VpcCongiguration object = new VpcCongiguration();
			object.setText(text);
			VpcCongigurationDAO ObjectDAO = DAOFactory.getInstance().getVpcCongigurationDAO();
			ObjectDAO.save(object);
			arrVpcCongiguration = null;
		}catch(Exception ex){
			
		}
	}
	
	public static void Delete(int id){
		try{
			
			VpcCongigurationDAO ObjectDAO = DAOFactory.getInstance().getVpcCongigurationDAO();
			VpcCongiguration object = ObjectDAO.findById(id);
			ObjectDAO.delete(object);
			arrVpcCongiguration = null;
		}catch(Exception ex){
			
		}
	}
}
